package com.ivanceras.client.widgets;

import com.google.gwt.core.client.GWT;
import com.google.gwt.dom.client.DivElement;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.SimplePanel;
import com.google.gwt.user.client.ui.Widget;
import com.google.gwt.user.client.ui.TextBox;
import com.ivanceras.shared.bo.Ad_column;
import com.ivanceras.shared.bo.Ad_field;
import com.ivanceras.shared.bo.Ad_reference;
import com.ivanceras.shared.util.ReferenceLookup;

public class AField extends Composite {

	private static AFieldUiBinder uiBinder = GWT.create(AFieldUiBinder.class);

	interface AFieldUiBinder extends UiBinder<Widget, AField> {
	}

	@UiField DivElement label;
	@UiField SimplePanel fieldWidget;
	
	TextBox textbox = null;
	
	public AField(Ad_field field) {
		initWidget(uiBinder.createAndBindUi(this));
		label.setInnerText(field.getName());
		Ad_column column = field.getAd_column();
		if(column != null){
			Ad_reference reference = column.getAd_reference();
			Widget widget = ReferenceLookup.getFieldEquiv(reference);
		}
		textbox = new TextBox();
		fieldWidget.setWidget(textbox);
	}
	
	public void setValue(Object value){
		if(value != null ){
			textbox.setText(value.toString());
		}
	}

}
